package com.fy.fyzf.presenter;

import com.fy.fyzf.api.SubscriberCallBack;
import com.fy.fyzf.base.BasePresenter;
import com.fy.fyzf.bean.AddPassengerBean;
import com.fy.fyzf.bean.AreaListBean;
import com.fy.fyzf.bean.HousesListBean;
import com.fy.fyzf.bean.PassengerDetailBean;
import com.fy.fyzf.bean.PassengerListBean;
import com.fy.fyzf.bean.BaseData;
import com.fy.fyzf.bean.SearchPassengerBean;
import com.fy.fyzf.view.PassengerCallBack;

import java.util.List;

public class PassengerPresnter extends BasePresenter<PassengerCallBack> {

    public PassengerPresnter(PassengerCallBack view) {
        super(view);
    }

    public void getPassengerList(SearchPassengerBean searchPassengerBean){
        addSubscription(mApiService.listCustomerByPage(searchPassengerBean), new SubscriberCallBack<BaseData<PassengerListBean>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<PassengerListBean> response) {
                mView.getPassengerListSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    //推荐房源
    public void getRecommendHousing(SearchPassengerBean searchPassengerBean){
        addSubscription(mApiService.recommendHousing(searchPassengerBean), new SubscriberCallBack<BaseData<HousesListBean>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<HousesListBean> response) {
                mView.getRecommendHousingSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getPassengerDetail(int id){
        addSubscription(mApiService.getCustomerDetail(id), new SubscriberCallBack<BaseData<PassengerDetailBean>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<PassengerDetailBean> response) {
                mView.getPassengerDetailSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getCollectHousing(SearchPassengerBean searchPassengerBean){
        addSubscription(mApiService.listCollectHousing(searchPassengerBean), new SubscriberCallBack<BaseData<HousesListBean>> (mView,false) {
            @Override
            protected void onSuccess(BaseData<HousesListBean> response) {
                mView.getCollectHousingSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }


    public void getMatchHousingList(SearchPassengerBean searchPassengerBean,boolean isLoading){

        addSubscription(mApiService.getMatchHousingList(searchPassengerBean), new SubscriberCallBack<BaseData<HousesListBean>>(mView,isLoading) {
            @Override
            protected void onSuccess(BaseData<HousesListBean> response) {
                mView.getMatchHousingSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void addCollectHousing(SearchPassengerBean searchPassengerBean,int position){
        addSubscription(mApiService.addCollectHousing(searchPassengerBean), new SubscriberCallBack<BaseData>(mView,true) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.collectHousingSuccess(response,position);
            }

            @Override
            protected void onError() {

            }
        });
    }


    public void removeCollectionHousing(SearchPassengerBean searchPassengerBean,int position){
        addSubscription(mApiService.removeCollectHousing(searchPassengerBean), new SubscriberCallBack<BaseData>(mView,true) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.removecollectHousingSuccess(response,position);
            }

            @Override
            protected void onError() {

            }
        });
    }


    public void addPassengerSource(AddPassengerBean addPassengerBean){
        addSubscription(mApiService.addCustomer(addPassengerBean), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.AddPassengerSourceSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }

    public void getSiteList(int id){
        addSubscription(mApiService.getallArea(id, 2), new SubscriberCallBack<BaseData<List<AreaListBean>>>(mView,true) {
            @Override
            protected void onSuccess(BaseData<List<AreaListBean>> response) {
                mView.getSiteListSuccess(response.data);
            }

            @Override
            protected void onError() {

            }
        });
    }

    /**
     * 修改客源
     */

    public void editPassenger(AddPassengerBean addPassengerBean){
        addSubscription(mApiService.editCustomer(addPassengerBean), new SubscriberCallBack<BaseData>(mView,false) {
            @Override
            protected void onSuccess(BaseData response) {
                mView.editPassengerSuccess(response);
            }

            @Override
            protected void onError() {

            }
        });
    }
}
